package cn.wolfcode.wms.query;

import java.util.Collections;
import java.util.List;

import lombok.Getter;
@Getter
public class PageResult {
	
	private Integer currentPage;
	private Integer pageSize;
	
	private List<?> listData;
	private Integer totalCount;
	
	private Integer totalPage;
	private Integer prevPage;
	private Integer nextPage;
	
	public PageResult() {}
	public PageResult(Integer currentPage, Integer pageSize, List<?> listData, Integer totalCount) {
		this.currentPage = currentPage;
		this.pageSize = pageSize;
		this.listData = listData;
		this.totalCount = totalCount;
		
		if (totalCount < pageSize) {
			this.totalPage=1;
			this.prevPage=1;
			this.nextPage=1;
			return;
		}
		
		this.totalPage=totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1;
		this.prevPage=currentPage - 1 > 0 ? currentPage - 1 : 1;
		this.nextPage=currentPage + 1 > totalPage ? totalPage : currentPage + 1;
	}
	//当总数数据等于0时
	public PageResult(Integer pageSize){
		 this(1,pageSize,Collections.EMPTY_LIST,0);
	}
}
